package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.bean.SemiProductQuality;
import com.example.spinning.mapper.SemiQualityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class SemiQualityService {
    @Autowired
    SemiQualityMapper semiQualityMapper;


    //增加操作
    public int addNewSemiQuality(SemiProductQuality semiProductQuality) {
        return semiQualityMapper.addNewSemiQuality(semiProductQuality);
    }

    //删除操作
    public boolean deleteSemiQualityById(Long[] ids) {
        int result = semiQualityMapper.deleteSemiQualityById(ids);
        return result == ids.length;
    }

    //查询并分页
//    public PageInfo<SemiQuality> findPage(Integer page, Integer size, String batch_no,String name, Date date) {
//
//        SemiQuality semiQuality = new SemiQuality();
//        semiQuality.setBatch_no(batch_no);
//        semiQuality.setName(name);
//        semiQuality.setDate(date);
//
//        PageHelper.startPage(page,size);
//        List<SemiQuality> list = semiQualityMapper.select(semiQuality);
//        PageInfo<SemiQuality> pageInfo = new PageInfo<>(list);
//
//        return pageInfo;
//    }
    public PaginationResult<SemiProductQuality> findPage(Integer page, Integer size, String batch_no, String name, Date date) {

        QueryWrapper<SemiProductQuality> wrapper = new QueryWrapper();
        if (null!=batch_no)
            wrapper.eq("batch_no", batch_no);
        if (null!=name)
            wrapper.eq("name", name);
        if (null!=date)
            wrapper.eq("date", date);

        Page<SemiProductQuality> pages = new Page<>(page,size);
        semiQualityMapper.selectPage(pages, wrapper);
        int total = semiQualityMapper.selectCount(wrapper);
        List<SemiProductQuality> list = pages.getRecords();

        PaginationResult<SemiProductQuality> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int updateCategoryById(SemiProductQuality semiProductQuality) {
        int result = semiQualityMapper.updateById(semiProductQuality);
        return result;
    }

    }
